﻿using System.Collections.Generic;
using RSSNewsGrabberModule.Converters;
using RSSNewsGrabberModule.Interfaces;
using RSSNewsGrabberModule.Mapping;

namespace RssDataProviderUnitTests
{
    public static class TestHelper
    {
        public static FieldsMapping CreateTestFieldsMappings()
        {
            //root levels config
            var roots = new LinkedList<string>();
            roots.AddLast("rss");
            roots.AddLast("channel");
            //create map
            var fieldMap = new  FieldsMapping(roots,"header","item");
            //add header section
            fieldMap.Header.Add("title",GetFieldInfo("Title","single",new DefaultConverter()));
            fieldMap.Header.Add("link", GetFieldInfo("Link", "single", new DefaultConverter()));
            fieldMap.Header.Add("description", GetFieldInfo("Description", "single", new DefaultConverter()));
            fieldMap.Header.Add("publishedDate", GetFieldInfo("PubDate", "single", new DateTimeConverter()));
            fieldMap.Header.Add("categories", GetFieldInfo("Category", "multi", new StringCollectionConverter()));
            //add item section
            fieldMap.Item.Add("title", GetFieldInfo("Title", "single", new DefaultConverter()));
            fieldMap.Item.Add("link", GetFieldInfo("Link", "single", new DefaultConverter()));
            fieldMap.Item.Add("description", GetFieldInfo("Description", "single", new DefaultConverter()));
            fieldMap.Item.Add("publishedDate", GetFieldInfo("PubDate", "single", new DateTimeConverter()));
            fieldMap.Item.Add("categories", GetFieldInfo("Category", "multi", new StringCollectionConverter()));
            return fieldMap;
        }

        private static FieldInfo GetFieldInfo(string name,string type,IConverter converter)
        {
            return new FieldInfo(type,name,converter);
        }
    }
}
